package com.stockz.downloaderx;

import java.util.List;

import com.stockz.downloaderx.Downloader.Callback.EVENT;
import com.stockz.downloaderx.Downloader.Callback.TYPE;

public abstract class AbstractDownloader implements Downloader {
	
	private boolean cancelRequested = false;
	private boolean running = false;

	protected void executeCallbacks(Download download, EVENT event, TYPE type, List<Callback> callbackList){
		download.setEvent(event);
		download.setType(type);
		for(Callback callback : callbackList){
			callback.execute(download);
		}
	}
	
	@Override
	public boolean isRunning() {
		return running;
	}
	
	protected void setRunning(boolean running) {
		this.running = running;
	}
	
	public void reset(){
		this.cancelRequested = false;
	}
	
	public boolean isCancelRequested() {
		return cancelRequested;
	}
	
	@Override
	public void cancel() {
		this.cancelRequested = true;
	}

}
